﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuanLyThongTinNhanKhau.model.DAO
{
    class TachHoKhauDAO
    {
        SQLServiceDAO service = new SQLServiceDAO();

        internal System.Data.DataTable loadLeftField(string maNhanKhau)
        {
            String sql = "select HoTen, CMND, NgaySinh from NHANKHAU where MaNhanKhau = '"+maNhanKhau+"'";
            return service.getDataTable(sql);
        }

        internal DataTable loadHoKhau(String maHoKhau)
        {
            DataTable dt = new DataTable();
            String sql = "select * from SOHOKHAU where TinhTrang = 'Enable' and MaHoKhau != '"+maHoKhau+"'";
            dt = service.getDataTable(sql);
            return dt;
        }

        internal DataTable btnTimKiem(string maHoKhau, string hoTen, string maHoKhauCu)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("select * from SOHOKHAU where TinhTrang = 'Enable' and MaHoKhau != '"+maHoKhauCu+"'");

            if (maHoKhau != "")
            {
                sb.Append(" and MaHoKhau Like N'%" + maHoKhau + "%'");
            }

            if (hoTen != "")
            {
                sb.Append(" and TenChuHo LIKE N'%" + hoTen + "%'");
            }

            DataTable dt = service.getDataTable(sb.ToString());
            return dt;
        }

        internal bool btnLuu(string maHoKhauMoi, string maNhanKhau, string quanHeChuHo)
        {
            String sql = "update QUANHE set MaHoKhau = '" + maHoKhauMoi + "', QuanHeChuHo = N'" + quanHeChuHo + "' where MaNhanKhau = '" + maNhanKhau + "'";
            return service.executeNonQuery(sql);
        }
    }
}
